/*
 * @Description:  任务
 * @Author: Myruun
 * @Date: 2021-04-19 16:03:57
 * @LastEditors: Myruun
 * @LastEditTime: 2021-07-29 10:54:39
 * @FilePath: \serve\controller\task.js
 */
const mysqlQuery = require("../unit/mysql.js");

// 获取任务列表
exports.Index = async (ctx, next) => {
  let body = ctx.request.body;
  const id = body.id || "";
  let sql = "";
  if (id) {
    sql =
      "SELECT * FROM task  WHERE state = '1' and id ='" +
      id +
      "' order by id desc";
  } else {
    sql = "SELECT * FROM task  WHERE state = '1' order by id desc";
  }
  let obj = await mysqlQuery(sql);
  ctx.response.body = obj;
};

// 添加任务
exports.add = async (ctx, next) => {
  let body = ctx.request.body;
  const content = body.content || "";
  const time = Math.round(new Date() / 1000);
  let sql = `INSERT INTO task (content, creation_time, state, user_id, id, update_time) VALUES ('${content}','${time}',1,1,0,'${time}')`;
  let obj = await mysqlQuery(sql);
  ctx.response.body = { code: 200, data: { msg: "添加成功" } };
};
